package com.ywjt.platformbusiness.store.fragment;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.ywjt.platformbusiness.R;
import com.ywjt.platformbusiness.base.BaseVPFragment;
import com.ywjt.platformbusiness.store.adapter.UpGoodsFragmentAdapter;
import com.ywjt.platformbusiness.util.WarningDialog;

import java.util.ArrayList;
import java.util.List;

public class StoreTypeGoodsFragment extends BaseVPFragment {
    private Context context;
    private List<Integer> banners;
    private RecyclerView rcGoods;
    private UpGoodsFragmentAdapter goodsAdapter;
    private PopupWindow popupWindow;

    public static StoreTypeGoodsFragment newInstance(String type) {
        Bundle arguments = new Bundle();
        arguments.putString("type",type);
        StoreTypeGoodsFragment fl = new StoreTypeGoodsFragment();
        fl.setArguments(arguments);
        return fl;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.goods_type_fragment,container,false);
        initView(view);
        return view;
    }


    @Override
    protected void onFragmentVisibleChange(boolean isVisible) {

    }


    public void initView(View view){
        context=getActivity();
        rcGoods=view.findViewById(R.id.rcCommon);
        banners=new ArrayList<>();
        banners.add(R.mipmap.icon_classify_banner_img);
        banners.add(R.mipmap.icon_classify_banner_img);
        banners.add(R.mipmap.icon_classify_banner_img);
        banners.add(R.mipmap.icon_classify_banner_img);
        banners.add(R.mipmap.icon_classify_banner_img);
        banners.add(R.mipmap.icon_classify_banner_img);
        banners.add(R.mipmap.icon_classify_banner_img);
        banners.add(R.mipmap.icon_classify_banner_img);




//        goodsAdapter=new UpGoodsFragmentAdapter(banners);
//        rcGoods.setLayoutManager(new GridLayoutManager(context,2,RecyclerView.VERTICAL,false));
//        rcGoods.setAdapter(goodsAdapter);
//        goodsAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
//            @Override
//            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
//                Activity_GoodsDetail.actionStart(context);
//            }
//        });
//        goodsAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
//            @Override
//            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
//                switch (view.getId()){
//                    case R.id.ivMore:
//                        //更多 弹出来弹窗
//                        View inflate = LayoutInflater.from(getContext()).inflate(R.layout.popu_up_goods,null);
//                        LinearLayout llUpGoods=inflate.findViewById(R.id.llUpGoods);
//
//                        llUpGoods.setOnClickListener(new View.OnClickListener() {
//                            @Override
//                            public void onClick(View v) {
//                                WarningDialog upDialog=new WarningDialog(context,"确认上架商品吗？","取消","确认","提示");
//                                upDialog.setClicklistener(new WarningDialog.ClickListenerInterface() {
//                                    @Override
//                                    public void doCancel() {
//                                        upDialog.dismiss();
//                                    }
//
//                                    @Override
//                                    public void doConfirm() {
//                                        upDialog.dismiss();
//                                    }
//                                });
//                                upDialog.show();
//                            }
//                        });
//                        LinearLayout llDelete=inflate.findViewById(R.id.llDelete);
//                        llDelete.setOnClickListener(new View.OnClickListener() {
//                            @Override
//                            public void onClick(View v) {
//                                WarningDialog delDialog=new WarningDialog(context,"确认删除商品吗？","取消","确认","提示");
//                                delDialog.setClicklistener(new WarningDialog.ClickListenerInterface() {
//                                    @Override
//                                    public void doCancel() {
//                                        delDialog.dismiss();
//                                    }
//
//                                    @Override
//                                    public void doConfirm() {
//                                        delDialog.dismiss();
//                                    }
//                                });
//                                delDialog.show();
//                            }
//                        });
//
//                        popupWindow = new PopupWindow(inflate, RelativeLayout.LayoutParams.WRAP_CONTENT,
//                                RelativeLayout.LayoutParams.WRAP_CONTENT);
//                        //设置背景,这个没什么效果，不添加会报错
//                        popupWindow.setBackgroundDrawable(new BitmapDrawable());
//                        //设置点击弹窗外隐藏自身
//                        popupWindow.setFocusable(true);
//                        popupWindow.setOutsideTouchable(true);
//                        //相对于某一个控件的位置
//                        popupWindow.showAsDropDown(view,-100,-100);
//                        break;
//                }
//            }
//        });

    }

    /**
     * 在fragment首次可见时回调，可用于加载数据，防止每次进入都重复加载数据
     */
    @Override
    protected void onFragmentFirstVisible() {

    }
}
